About 3786 letters

About 19 minutes

#format

Description: Format a value (calls the object's __format__ method).

def format(value, format_spec=''): ''' Format a value using format_spec. :param value: A variable :param format_spec: Format specification :return: The formatted value '''

Example:

# Numeric formatting print(format(3.14159, ".2f")) # Output: '3.14' print(format(1000000, ",")) # Output: '1,000,000' # Alignment and padding print(format("hello", "^10")) # Output: ' hello ' (center-aligned, width 10) print(format(42, "05d")) # Output: '00042' (zero-padded, width 5) # Base conversion print(format(10, "b")) # Output: '1010' (binary) print(format(255, "x")) # Output: 'ff' (lowercase hexadecimal)

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

#Format Specification

format_spec ::= [options][width][grouping]["." precision][type] options ::= [[fill]align][sign]["z"]["#"]["0"] fill ::= <any character> align ::= "<" | ">" | "=" | "^" sign ::= "+" | "-" | " " width ::= digit+ grouping ::= "," | "_" precision ::= digit+ type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"

#Alignment Options

OptionDescription
<Left-align (default for text)
>Right-align (default for numbers)
=Padding after sign but before digits
^Center-align

#Sign Options

OptionDescription
+Show sign for both positive and negative numbers
-Show sign only for negative numbers (default)
(space)Leading space for positive, - for negative

#Separator Options

OptionDescription
,Use comma as thousands separator
_Use underscore as thousands separator

#Integer Type Options

OptionDescription
bBinary
dDecimal
oOctal
xHexadecimal (lowercase)
XHexadecimal (uppercase)
nLike d, but uses locale-specific separators
cConvert integer to corresponding Unicode character before printing

#Floating Point Type Options

OptionDescription
eScientific notation (lowercase)
EScientific notation (uppercase)
fFixed-point notation (default 6 decimals)
FSame as f, but uses uppercase
gGeneral format (lowercase)
GGeneral format (uppercase)
nLike g, but uses locale-specific separators
%Percentage (multiplies by 100 and adds %)

Created in 6/9/2025

Updated in 6/9/2025